// 导入用户集合
const { PageRights } = require('../../../model/pageRights');

module.exports = async (req, res) => {
  let grade = 1
  if (req.body.parentId) {
    current = await PageRights.findOne({_id: req.body.parentId})
    console.log(current)
    console.log(current.grade)
    grade = current.grade + 1
  }
  await PageRights.create({
    ...req.body,
    grade,
  }).then(item => {
    console.log(item)
    res.json({
        data: item,
        message: '添加成功！'
    })
  }).catch((err) => {
    res.status(403)
    res.json({
        log: err,
        message: '添加失败！'
    })
  })
}